package com.herench.bs.transfer;
import com.herench.bs.model.Doctor;
import com.herench.bs.model.HospitalDept;

import java.util.*;

/**
 * Created by ThinkPad on 2017/9/1.
 */
public class Dialect {


    private static Map<String, String> clinicMap = new HashMap<>();

    private static Map<String, String> datePeriodMap = new HashMap<>();

    private static Map<String, String> orderStatusCodeMap = new HashMap<>();

    private static Map<String, String> orderStatusMap = new HashMap<>();

    private static Map<String, Doctor> doctorMap = new HashMap<>();

    private static Map<String, HospitalDept> deptMap = new HashMap<>();

    private static Map<String, String> appointStatusMap = new HashMap<>();

    private static Map<String, String> ChargeMap = new HashMap<>();

    private static Map<String, String> subCostTypeCodeMap = new HashMap<>();

    private static Map<String, String> subCostTypeNameMap = new HashMap<>();

    private static Map<String, String> doctorTitleNameMap = new HashMap<>();

    private static Map<String, String> callNoStateMap = new HashMap<>();

    private static Map<String, String> ampmNameMap = new HashMap<>();

    public static final String SUCCESSFUL_STATE = "0";

    /**
     * 獲取數據件數為 0 件
     */
    public static final String SUCCESSFUL_ZERO = "1403";

    public static final String HOSPITAL_NAME = "天津市胸科医院";
    /**
     * MAX_BINDING_NUMBER 就诊人绑定人数上限
     */
    public static final int MAX_BINDING_NUMBER = 5;


    public static int getMaxBindingNumber() {
        return MAX_BINDING_NUMBER;
    }

    public static String getHospitalName() {
        return HOSPITAL_NAME;
    }

    public static String getSuccessfulState() {
        return SUCCESSFUL_STATE;
    }
    public static String getSuccessfulZero() {
        return SUCCESSFUL_ZERO;
    }

    static {
        clinicMap.put("特需专家", "0");
        clinicMap.put("专家", "1");
        clinicMap.put("主任", "2");
        clinicMap.put("副主任", "3");
        clinicMap.put("普通", "4");
        clinicMap.put("本院职工", "5");
        clinicMap.put("急诊", "6");
        clinicMap.put("老年", "7");
        clinicMap.put("简易", "8");
        clinicMap.put("义诊", "9");

        datePeriodMap.put("1", "上午");
        datePeriodMap.put("2", "下午");
        datePeriodMap.put("3", "白天");
        datePeriodMap.put("7", "昼夜");
        datePeriodMap.put("4", "夜间");
        datePeriodMap.put("5", "前夜");
        datePeriodMap.put("6", "后夜");

        orderStatusMap.put("成功", "0");
        orderStatusMap.put("失败", "1");
        orderStatusMap.put("已预约", "2");
        orderStatusMap.put("已导出", "2");
        orderStatusMap.put("挂号成功", "3");
        orderStatusMap.put("已过号", "4");
        orderStatusMap.put("已取消", "5");
        orderStatusMap.put("已退号", "6");
        orderStatusMap.put("未付费", "7");
        orderStatusMap.put("已付费", "8");
        orderStatusMap.put("已执行", "9");
        orderStatusMap.put("已退费", "10");
        orderStatusMap.put("挂号交易中间状态", "11");
        orderStatusMap.put("诊间交易中间状态", "12");
        orderStatusMap.put("未知", "13");
        orderStatusMap.put("已就诊", "14");
        orderStatusMap.put("挂号失败", "15");

        appointStatusMap.put("0", "已预约");
        appointStatusMap.put("1", "已取消");
        appointStatusMap.put("2", "已挂号");
        appointStatusMap.put("3", "已就诊");
        appointStatusMap.put("4", "挂号交易未完成");
        appointStatusMap.put("5", "预约报到交易未完成");
        appointStatusMap.put("7", "已撤销");
        appointStatusMap.put("9", "已退号");


        orderStatusCodeMap.put("成功", "0");
        orderStatusCodeMap.put("失败", "1");
        orderStatusCodeMap.put("已预约", "2");
        orderStatusCodeMap.put("已导出", "2");
        orderStatusCodeMap.put("挂号成功", "3");
        orderStatusCodeMap.put("已过号", "4");
        orderStatusCodeMap.put("已取消", "5");
        orderStatusCodeMap.put("已退号", "6");
        orderStatusCodeMap.put("9", "6");//9:HIS退号；6：已退号；
        orderStatusCodeMap.put("未付费", "7");
        orderStatusCodeMap.put("已付费", "8");
        orderStatusCodeMap.put("已执行", "9");
        orderStatusCodeMap.put("已退费", "10");
        orderStatusCodeMap.put("挂号交易中间状态", "11");
        orderStatusCodeMap.put("诊间交易中间状态", "12");
        orderStatusCodeMap.put("未知", "13");
        orderStatusCodeMap.put("已就诊", "14");
        orderStatusCodeMap.put("挂号失败", "15");


        subCostTypeCodeMap.put("处方", "1");
        subCostTypeCodeMap.put("检查", "2");
        subCostTypeCodeMap.put("治疗", "3");
        subCostTypeCodeMap.put("麻醉", "4");
        subCostTypeCodeMap.put("血费", "5");
        subCostTypeCodeMap.put("材料", "6");
        subCostTypeCodeMap.put("床位", "7");
        subCostTypeCodeMap.put("护理", "8");
        subCostTypeCodeMap.put("膳食", "9");
        subCostTypeCodeMap.put("其他", "0");

        subCostTypeNameMap.put("1", "处方");
        subCostTypeNameMap.put("2", "检查");
        subCostTypeNameMap.put("3", "治疗");
        subCostTypeNameMap.put("4", "麻醉");
        subCostTypeNameMap.put("5", "血费");
        subCostTypeNameMap.put("6", "材料");
        subCostTypeNameMap.put("7", "床位");
        subCostTypeNameMap.put("8", "护理");
        subCostTypeNameMap.put("9", "膳食");
        subCostTypeNameMap.put("0", "其他");

        doctorTitleNameMap.put("0", "无");
        doctorTitleNameMap.put("1", "副主任医师");
        doctorTitleNameMap.put("2", "医师");
        doctorTitleNameMap.put("3", "主管技师");
        doctorTitleNameMap.put("4", "主任护师");
        doctorTitleNameMap.put("5", "主任医师");
        doctorTitleNameMap.put("6", "主治医师");

        callNoStateMap.put("0", "已挂号");
        callNoStateMap.put("1", "已到");
        callNoStateMap.put("3", "过号");
        callNoStateMap.put("5", "已诊");
        callNoStateMap.put("9", "退号");
        callNoStateMap.put("-1", "其他");

        ampmNameMap.put("1","上午");
        ampmNameMap.put("2","下午");
    }

    public static String getCallNoState(String subCostTypeCode) {
        String name = callNoStateMap.get(subCostTypeCode);
        return name != null ? name : "";
    }

    public static String getAmpmName(String subCostTypeCode) {
        String name = ampmNameMap.get(subCostTypeCode);
        return name != null ? name : "";
    }

    public static String getDoctorTitleName(String subCostTypeCode) {
        String name = doctorTitleNameMap.get(subCostTypeCode);
        return name != null ? name : "";
    }

    public static String getSubCostTypeName(String subCostTypeCode) {
        String name = subCostTypeNameMap.get(subCostTypeCode);
        return name != null ? name : "0";
    }

    public static String getSubCostTypeCode(String subCostTypeName) {
        String code = subCostTypeCodeMap.get(subCostTypeName);
        return code != null ? code : "0";
    }

    public static String getClinicTypeCode(String clinicTypeName) {
        String code = clinicMap.get(clinicTypeName);
        return code != null ? code : "-1";
    }

    public static String getClinicType(String code) {
        for (Map.Entry<String, String> entry : clinicMap.entrySet()) {
            if (entry.getValue().equals(code)) {
                return entry.getKey();
            }
        }
        return "-1";

    }


    public static String getOrderStatusCode(String orderStatus) {
        String code = orderStatusCodeMap.get(orderStatus);
        return code != null ? code : "-1";
    }

    public static String getDayOfWeek(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        switch (calendar.get(Calendar.DAY_OF_WEEK)) {
            case 1:
                return "星期日";
            case 2:
                return "星期一";
            case 3:
                return "星期二";
            case 4:
                return "星期三";
            case 5:
                return "星期四";
            case 6:
                return "星期五";
            case 7:
                return "星期六";
            default:
                return "";
        }
    }

    public static String getAmpmCode(String timeDesc) {
        for (Map.Entry<String, String> entry : datePeriodMap.entrySet()) {
            if (entry.getValue().equals(timeDesc)) {
                return entry.getKey();
            }
        }
        return "-1";
    }

    public static void addDoctor(Doctor doctor) {
        if (doctor != null) {
            doctorMap.put(doctor.getDoctorCode(), doctor);
        }
    }

    public static void addDoctor(Collection<Doctor> doctors) {
        if (doctors != null) {
            Iterator<Doctor> doctorIterator = doctors.iterator();
            while (doctorIterator.hasNext()) {
                Doctor doctor = doctorIterator.next();
                doctorMap.put(doctor.getDoctorCode(), doctor);
            }
        }
    }

    public static Doctor getDoctor(String doctorCode) {
        return doctorMap.get(doctorCode);
    }


    public static String getAmpmValue(String ampm) {
        return datePeriodMap.get(ampm);
    }

    public static String getAppointStatusCode(String status) {
        for (Map.Entry<String, String> entry : appointStatusMap.entrySet()) {
            if (entry.getValue().equals(status)) {
                return entry.getKey();
            }
        }
        return "-1";
    }


    public static boolean ifContainCategory(String targetValue) {
        List<String> clinicList = new ArrayList<>();
        clinicList.add("特需专家");
        clinicList.add("专家");
        clinicList.add("主任");
        clinicList.add("副主任");
        clinicList.add("普通");
        clinicList.add("老年");
        clinicList.add("义诊");
        clinicList.add("简易门诊");
        return clinicList.contains(targetValue);
    }

    public static String getAppointStatusName(String code) {
        return appointStatusMap.get(code);
    }
}
